#ifndef LOADEROFF_H
#define LOADEROFF_H
#include <iostream>
#include <fstream>
#include "Mesh.h"
#include "Export.h"
#include "ILoader.h"
namespace glow
{
class SHARED LoaderOFF : public ILoader<Mesh_data>
{
	public :
		Mesh_data * load (std::string filename)
		{
			Mesh_data * Mp =new Mesh_data;
			
	        ifstream file(filename.c_str(), ios::in);
		
	        if(file)
	        {
		  
		  std::string filetype;
		  file >> filetype;
		  
		  if (filetype=="OFF")
		    {
		     unsigned int trashint=0;
		      file >> Mp->_nb_vertices >> Mp->_nb_index >> trashint;
		      /* tableau de points */
		      Mp->_vertices =new float[Mp->_nb_vertices*3];
		      Mp->_index=new unsigned int[Mp->_nb_index*3];	 
		      for (unsigned int i = 0; i<Mp->_nb_vertex*3; i = i+3)
			{
			  file >> Mp->_vertices[i] >> Mp->_vertices[i+1] >> Mp->_vertices [i+2];
			}
		     
		      for (unsigned int j= 0 ;j<Mp->_nb_index*3 ; j=j+4)
			{
			  file >> _trashint >> Mp->_index[j] >> Mp->_index[j+1] >> Mp->_index[j+2];
			}
		     
		    }
		  
		  else 
		    {
		      std::cout<< "type de fichier non pris en charge"<<std::endl;
		    }
		  
		  file.close();
		  
	        }
	        else
	                std::cerr << "Impossible d'ouvrir le fichier !" << std::endl;
	 
	        return Mp;
	}

	
};
}
#endif
